home *** CD-ROM | disk | FTP | other *** search
- head 1.4;
- branch ;
- access ;
- symbols sprited:1.4.1;
- locks ; strict;
- comment @ * @;
-
-
- 1.4
- date 90.09.27.04.42.29; author rab; state Exp;
- branches 1.4.1.1;
- next 1.3;
-
- 1.3
- date 88.06.18.17.17.24; author ouster; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.05.21.11.49.05; author ouster; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.05.20.15.49.12; author ouster; state Exp;
- branches ;
- next ;
-
- 1.4.1.1
- date 91.12.02.20.35.10; author kupfer; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.4
- log
- @Fixed MemChunkAlloc to handle misaligned addresses returned by sbrk.
- @
- text
- @/*
- * MemChunkAlloc.c --
- *
- * Source code for the "MemChunkAlloc" procedure, which is used
- * internally by the memory allocator to create new memory for
- * user-level programs. Different programs or uses of the
- * allocator may replace this version of MemChunkAlloc with
- * something appropriate to the particular program. See memInt.h
- * for overall information about how the allocator works.
- *
- * Copyright 1985, 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemChunkAlloc.c,v 1.3 88/06/18 17:17:24 ouster Exp Locker: rab $ SPRITE (Berkeley)";
- #endif not lint
-
- #include "memInt.h"
- #include <stdio.h>
- #include <sys/types.h>
-
- /*
- * UNIX library imports:
- */
-
- extern caddr_t sbrk();
-
- /*
- * The variables below don't exactly belong in this file, but they
- * need to be someplace that's use-dependent (just like MemChunkAlloc)
- * so that they can be initialized differently for different uses
- * of the allocator (e.g. kernel vs. user).
- */
-
- extern int fprintf();
- int (*memPrintProc)() = fprintf;
- ClientData memPrintData = (ClientData) stdout;
-
- /*
- *----------------------------------------------------------------------
- *
- * MemChunkAlloc --
- *
- * malloc calls this procedure to get another region of storage
- * from the system (i.e. whenever the storage it's gotten so far
- * is insufficient to meet a request). The actual size returned
- * may be greater than size but not less. This region now becomes
- * the permanent property of malloc, and will never be returned.
- *
- * Results:
- * The return value is a pointer to a new block of memory that
- * is size bytes long.
- *
- * Side effects:
- * The virtual address space of the process is extended.
- * If the VAS can't be increased, the process is terminated.
- *
- *----------------------------------------------------------------------
- */
-
- Address
- MemChunkAlloc(size)
- int size; /* Number of bytes desired. */
- {
- Address result;
- int misAlignment;
-
- result = (Address) sbrk(size);
- if (result == (Address) -1) {
- panic("MemChunkAlloc couldn't extend heap");
- return(0); /* should never get here */
- }
- /* Make sure `result' is aligned to hold at least a double */
- if ((misAlignment = (int) result & 7) != 0) {
- result += 8 - misAlignment;
- (Address) sbrk(8 - misAlignment);
- }
- return result;
- }
- @
-
-
- 1.4.1.1
- log
- @Initial branch for Sprite server.
- @
- text
- @d22 1
- a22 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemChunkAlloc.c,v 1.4 90/09/27 04:42:29 rab Exp $ SPRITE (Berkeley)";
- @
-
-
- 1.3
- log
- @Use panic instead of Sys_Panic.
- @
- text
- @d22 1
- a22 1
- static char rcsid[] = "$Header: MemChunkAlloc.c,v 1.2 88/05/21 11:49:05 ouster Exp $ SPRITE (Berkeley)";
- d73 1
- d79 5
- @
-
-
- 1.2
- log
- @Change to use sbrk.
- @
- text
- @d22 1
- a22 1
- static char rcsid[] = "$Header: MemChunkAlloc.c,v 1.1 88/05/20 15:49:12 ouster Exp $ SPRITE (Berkeley)";
- d76 1
- a76 1
- MemPanic("MemChunkAlloc couldn't extend heap");
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d22 1
- a22 1
- static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
- a25 1
- #include "vm.h"
- d27 1
- d30 1
- a30 4
- * NextAddr is the location of the first as-yet-unallocated byte in
- * the heap. It's used by MemCunkAlloc to increase the heap size
- * and to emulate brk and sbrk. PageSize is really the size of a
- * memory page minus 1.
- d33 1
- a33 2
- static Address nextAddr;
- static int pageSize;
- a35 7
- * Macro to compute for any address, the first addresss of the page
- * it is on.
- */
-
- #define FirstAddrOnPage(address) (((int) (address)) & (~pageSize))
-
- /*
- d51 1
- a51 1
- * malloc will call MemChunkAlloc to get another region of storage
- a71 1
- ReturnStatus status;
- a72 3
- extern int end; /* Symbol defined by loader to be the first
- * location above all data. */
- static Boolean initialized = FALSE;
- d74 4
- a77 15
- if (!initialized) {
- initialized = TRUE;
-
- /*
- * Get the system page size and calculate the address in the heap
- * after the end of data to start allocating chunks from.
- */
-
- if (Vm_PageSize(&pageSize) != SUCCESS) {
- MemPanic("Mem ChunkInit: failed to get page size");
- return; /* should never get here */
- }
- pageSize -= 1;
-
- nextAddr = (Address) &end;
- a78 21
-
- /*
- * Check to see if the request is already on a page that is mapped so
- * we can avoid a system call.
- *
- * If the starting address of the request is on the same page as
- * the ending address, then the requested block is already mapped
- * and the system call can be avoided.
- */
-
- if(FirstAddrOnPage(nextAddr - 1) != FirstAddrOnPage(nextAddr + size)) {
- status = Vm_CreateVA(nextAddr, size);
- if (status != SUCCESS) {
- MemPanic("MemChunkAlloc: failed to create VA");
- return(0); /* should never get here */
- }
- }
-
- result = nextAddr;
- nextAddr += size;
-
- a79 32
- }
-
- /*
- *----------------------------------------------------------------------
- *
- !<arch>
- __.SYMDEF 595480750 341 155 100664 182 `